/* eslint-disable @typescript-eslint/no-explicit-any */
/*
 *  Copyright 2021 Collate
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

 /**
 * 此模式定义事件发布作业
 */
export interface EventPublisherJob {
    /**
     * 在故障时提供After，以在问题解决后开始重新索引
     */
    afterCursor?: string;
    /**
     * 一批中发送的事件的最大数量（默认为10）
     */
    batchSize?: number;
    /**
     * 要重新索引的实体列表
     */
    entities?: string[];
    /**
     * 作业中的故障列表
     */
    failure?: IndexingAppError;
    /**
     * 结果的名称
     */
    name?: string;
    /**
     * 此模式定义发布器运行模式
     */
    recreateIndex?: boolean;
    /**
     * 使用更新的语言重新创建索引
     */
    searchIndexMappingLanguage?: SearchIndexMappingLanguage;
    stats?:                      Stats;
    /**
     * 此模式定义发布器运行作业状态
     */
    status:    Status;
    timestamp: number;
}

/**
 * 作业中的故障列表
 *
 * This schema defines Event Publisher Job Error Schema.
 */
export interface IndexingAppError {
    errorSource?:      ErrorSource;
    failedCount?:      number;
    failedEntities?:   EntityError[];
    lastFailedCursor?: string;
    message?:          string;
    reason?:           string;
    stackTrace?:       string;
    submittedCount?:   number;
    successCount?:     number;
}

export enum ErrorSource {
    Job = "Job",
    Processor = "Processor",
    Reader = "Reader",
    Sink = "Sink",
}

/**
 * Entity And Message Scehma in case of failures.
 */
export interface EntityError {
    entity?:  any;
    message?: string;
}

/**
 * 使用更新的语言重新创建索引
 *
 * This schema defines the language options available for search index mappings.
 */
export enum SearchIndexMappingLanguage {
    En = "EN",
    Jp = "JP",
    Zh = "ZH",
}

export interface Stats {
    entityStats?: StepStats;
    jobStats?:    StepStats;
}

/**
 * 不同步骤的统计信息，包括Reader、Processor、Writer
 */
export interface StepStats {
    /**
     * 总失败记录数
     */
    failedRecords?: number;
    /**
     * 总成功记录数
     */
    successRecords?: number;
    /**
     * 总失败记录数
     */
    totalRecords?: number;
    [property: string]: any;
}

/**
 * 此模式定义发布器运行作业状态
 */
export enum Status {
    Active = "active",
    ActiveError = "activeError",
    Completed = "completed",
    Failed = "failed",
    Running = "running",
    Started = "started",
    Stopped = "stopped",
    Success = "success",
}
